require(['./config'],()=>{
    require(['cookie','jquery'], (cookie)=> {
        class Login{
            constructor(){
                this.loginEvent()
            }
            loginEvent(){
                $('#loginBtn').on('click',()=>{
                    const name = $('#loginName').val();
                    const pwd = $('#loginPwd').val();
                    console.log(name,pwd)
                    let userList = JSON.parse(localStorage.getItem('userList'))
                    if(userList){
                        const isExist = userList.some(user=>{
                            return user.name === name && user.pwd === pwd
                        })
                        console.log(isExist)
                        if(isExist){
                            if($('.isRemember').prop('checked')){
                                $.cookie('username',name,{path:'/',expires: 365})
                            }else{
                                $.cookie('username',name,{path:'/'})
                            }                    
                            $('.message').html('登陆成功，即将切换到首页')
                            setTimeout(()=>{
                                window.open('/index.html','_self')
                            },2000)
                        }else{
                            $('.message').html('密码或用户名错误，请重新输入')
                        }
                    }else{
                        $('.message').html('还没有账号和密码，请前去注册').css('color','red')
                        setTimeout(()=>{
                            window.open('/html/register.html','_self')
                        },2000)
                    }
                })
            }
        }
        return new Login()
    })
})


